package com.example.xunai.dto.response.conversation;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ConversationListResponse {
    private List<ConversationResponse> conversations;
    private Integer totalCount;
    private Integer page;
    private Integer size;
    private Boolean hasNext;
    private Boolean hasPrevious;
    private Integer totalPages;

    public static ConversationListResponse of(List<ConversationResponse> conversations, Integer totalCount,
                                              Integer page, Integer size) {
        int totalPages = (int) Math.ceil((double) totalCount / size);
        boolean hasNext = page < totalPages;
        boolean hasPrevious = page > 1;

        return ConversationListResponse.builder()
                .conversations(conversations)
                .totalCount(totalCount)
                .page(page)
                .size(size)
                .hasNext(hasNext)
                .hasPrevious(hasPrevious)
                .totalPages(totalPages)
                .build();
    }

    public static ConversationListResponse empty(Integer page, Integer size) {
        return ConversationListResponse.builder()
                .conversations(List.of())
                .totalCount(0)
                .page(page)
                .size(size)
                .hasNext(false)
                .hasPrevious(false)
                .totalPages(0)
                .build();
    }
}